<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	//返回链接
	$return['forward_url']=base64_encode('jy_xunichong/order.list//fromcreate=1');
	$isfollow=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');	
	if(!$isfollow && $_RQ['fromcreate'] && !$shopset['noshowqrcode']){
		$return['showwechatcode']=1;
	}
	$return['list']=array();
	$return['status']=isset($_RQ['status'])?$_RQ['status']:100;
	set_html('title','订单列表');
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(isset($_RQ['status']) && $_RQ['status'] !=100){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}else{
		$return['status']=100;
	}
	if(!empty($_RQ['ordersn'])){
		$params['ordersn']=intval($_RQ['ordersn']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_xunichong_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$item){
		$goods=pdo_get('jy_xunichong_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('title','image','price','oldprice','type','desc'));
		$item['goods']=$goods;
		$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		$item['typetitle']=$this->gift_type[$item['gift_type']];
		$item['statustitle']=$this->order_status[$item['status']];
	}
	$return['list']=$list;
	exi($return);
}
// js 获取数据
if($_RQ['op']=='gettanmus'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 30;
	$total='';
	$fields=array('id','mid','status');
	$list=pdo_getslice('jy_xunichong_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$item){
		$member=cfc('core')->member_show($item['mid']);
		$member['nickname']=mb_substr($member['nickname'],0,4,'utf-8').'***';
		$item['nickname']=$member['nickname'];
		$member['avatar']=$member['avatar']?:'../core/resource/images/nopic.jpg';
		$item['avatar']=tomedia($member['avatar']);
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_xunichong_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	exi($order['pay_id']);
}
if($_RQ['op']=='cancel'){
	$post=get_postdata();	
	$id=intval($post['id']);
	if($id){
		$this->model('model')->order_cancel($id);
		exi('取消成功！','','jy_xunichong/order.list/');		
	}else{		
		exi('取消失败！','error');
	}
}
if($_RQ['op']=='receive'){
	$post=get_postdata();
	$id=intval($post['id']);
	$this->model('model')->order_receive($id);
	exi('确认成功！');	
}

if($_RQ['op']=='sendsubmsg'){
	$id = intval($_RQ['id']);
	$this->model('order')->sendsubmsg($id);
	exi('success');	
}
if($_RQ['op']=='getnew'){
	$params=array(
		'status'=>1,
		'uniacid'=>$_SESSION['uniacid'],
	);
	$order=pdo_get('jy_xunichong_order',$params);
	if($order['id']){
		exi($order);
	}else{
		exi('none');
	}
}
?>